package types

import (
	

	
	
)

// Reference: https://www.ietf.org/rfc/rfc4120.txt
// Section: 5.2.9

// EncryptedData implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.9
type EncryptedData struct {
	EType  int32  `asn1:"explicit,tag:0"`
	KVNO   int    `asn1:"explicit,optional,tag:1"`
	Cipher []byte `asn1:"explicit,tag:2"`
}

// EncryptionKey implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.9
// AKA KeyBlock
type EncryptionKey struct {
	KeyType  int32  `asn1:"explicit,tag:0"`
	KeyValue []byte `asn1:"explicit,tag:1" json:"-"`
}

// Checksum implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.9
type Checksum struct {
	CksumType int32  `asn1:"explicit,tag:0"`
	Checksum  []byte `asn1:"explicit,tag:1"`
}

// Unmarshal bytes into the EncryptedData.
func ( *EncryptedData) ( []byte) error {
	,  := asn1.Unmarshal(, )
	return 
}

// Marshal the EncryptedData.
func ( *EncryptedData) () ([]byte, error) {
	,  := asn1.Marshal(*)
	if  != nil {
		return , 
	}
	return , nil
}

// Unmarshal bytes into the EncryptionKey.
func ( *EncryptionKey) ( []byte) error {
	,  := asn1.Unmarshal(, )
	return 
}

// Unmarshal bytes into the Checksum.
func ( *Checksum) ( []byte) error {
	,  := asn1.Unmarshal(, )
	return 
}

// GenerateEncryptionKey creates a new EncryptionKey with a random key value.
func ( etype.EType) (EncryptionKey, error) {
	 := EncryptionKey{
		KeyType: .GetETypeID(),
	}
	 := make([]byte, .GetKeyByteSize(), .GetKeyByteSize())
	,  := rand.Read()
	if  != nil {
		return , 
	}
	.KeyValue = 
	return , nil
}